﻿#include "mainwindow.h"
#include "login/logindlg.h"
#include <QApplication>
#include <QTextCodec>
#include <QFile>
#include"ufxconfig.h"
#include<QDesktopWidget>
#include"CtpInterface/ctpinterface.h"
#include <QMetaType>

//在此处初始化
UFXConfig* UFXConfig::instance = new UFXConfig();
MainWindow* g_pMainwindow;
CLoginDlg*  g_pLoginDlg;
CTPInterface* g_CTPInterface;

int main(int argc, char *argv[])
{
    qRegisterMetaType< QVector<int> >("QVector<int>");
    qRegisterMetaType< QList<QPersistentModelIndex> >("QList<QPersistentModelIndex>");
    qRegisterMetaType< QAbstractItemModel::LayoutChangeHint >("QAbstractItemModel::LayoutChangeHint");

    QApplication app(argc, argv);

    //加载QSS样式表
    QFile qss(":/TraderQss");
    qss.open(QFile::ReadOnly);
    qApp->setStyleSheet(qss.readAll());
    qss.close();

	g_CTPInterface = new CTPInterface;
    g_pLoginDlg = new CLoginDlg;
    g_pMainwindow = new MainWindow;    

    //登录
    int retVal = g_pLoginDlg->exec();
    //int retVal = 1;

    if(retVal == 1){
        QDesktopWidget* desktopWidget = QApplication::desktop();
        QRect screenRect = desktopWidget->screenGeometry();
        int ScreenW = screenRect.width();
        int ScreenH = screenRect.height();
        g_pMainwindow->resize(ScreenW/6*5,ScreenH);
        g_pMainwindow->move(0,0);
        g_pMainwindow->show();
        return app.exec();
    }else{
        return 0;
    }
}
